package com.uenpay.im.ui.old.activity.crowdfund;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.qyx.android.message.type.PacketType;
import com.uenpay.im.R;
import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.weight.RoundImageView;

import java.util.ArrayList;

/**
 * @author SL
 * @copyRight http://www.qiyunxin.com
 * @E-mail:
 * @date 创建时间：2016-5-7 下午9:04:45
 * @version 1.0
 * @function 众筹记录适配器
 */
public class CFRecordAdapter extends BaseAdapter {
	private Context mContext;
	private ArrayList<CFRecordEntity> arrayList = new ArrayList<CFRecordEntity>();

	public CFRecordAdapter(Context _Context,
			ArrayList<CFRecordEntity> _ArrayList) {
		arrayList = _ArrayList;
		mContext = _Context;
	}

	@Override
	public int getCount() {
		return arrayList == null ? 0 : arrayList.size();
	}

	@Override
	public Object getItem(int arg0) {
		return arrayList == null ? null : arrayList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		CFRecordViewHodler hodler = null;
		CFRecordEntity mCFRecordEntity = arrayList.get(arg0);
		if (arg1 == null) {
			hodler = new CFRecordViewHodler();
			arg1 = View.inflate(mContext, R.layout.item_cfrecord_layout, null);
			hodler.amount = (TextView) arg1.findViewById(R.id.amount_tv);
			hodler.nickname = (TextView) arg1.findViewById(R.id.nick_name_tv);
			hodler.createTime = (TextView) arg1.findViewById(R.id.create_date);
			hodler.avatarView = (RoundImageView) arg1
					.findViewById(R.id.avatar_iv);
			hodler.max_status = (ImageView) arg1.findViewById(R.id.max_status);
			arg1.setTag(hodler);
		} else {
			hodler = (CFRecordViewHodler) arg1.getTag();
		}
		hodler.amount.setText(mCFRecordEntity.amount);
		hodler.nickname.setText(mCFRecordEntity.nickname);
		hodler.createTime.setText(mCFRecordEntity.createtime);
		hodler.avatarView.SetUrl(APIConfiguration.getAvatarUrlNormal(
				mCFRecordEntity.custid, PacketType.PERSONAL));
		if (mCFRecordEntity.ismax == 0) {
			hodler.max_status.setVisibility(View.GONE);
		} else {
			hodler.max_status.setVisibility(View.VISIBLE);
		}
		return arg1;
	}

	private class CFRecordViewHodler {
		private TextView nickname, createTime, amount;
		private ImageView max_status;
		private RoundImageView avatarView;
	}

}
